<template>
  <div class="container">
    <div class="title">
      <span @click="oldFn"><van-icon name="revoke" style="margin: 0px 5px 0 0;" />返回</span>
      {{ this.title }}
    </div>
    <div class="content">
      <div
        class="conList"
        v-for="(item, index) in list"
        :key="index"
        @click="getInfo(item.id, item.username)"
      >
        <div class="image">
          <img :src="item.avatar" alt="" />
        </div>
        <div class="text">
          <div>{{ item.username }} ( {{ item.mobile || "暂无电话" }} )</div>
          <div>
            <span style="color: #999">推荐人姓名：</span>
            {{ item.tuijian_name }}
          </div>
        </div>
        <div class="number">
          <div>{{ item.team_num }}人</div>
          <div>团队人数</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getTeam, imgUrl } from "../../api/api";
import icon from "../../assets/icon4.png";
export default {
  data() {
    return {
      list: [],
      title: "我的团队",
      page: 1,
      pagesize: 1000,
      activeName: "1",
      oldList: [],
      oldName: [],
    };
  },
  methods: {
    getInfo(id, name) {
      const data = {
        user_id: id,
        page: this.page,
        pagesize: this.pagesize,
      };
      getTeam(data).then((res) => {
        this.$toast.clear();
        console.log("我的团队---", res.data.rows);
        this.oldName.push(this.title);
        this.oldList.push(this.list);
        this.list = res.data.rows;
        console.log(this.oldList, this.oldName);
        this.title = (name || "我") + "的团队";
        res.data.rows.forEach((item) => {
          item.avatar == ""
            ? (item.avatar = icon)
            : (item.avatar = imgUrl + item.avatar);
        });
      });
    },
    oldFn() {
      if(this.oldList.length == 1) return this.$router.go(-1)
      this.list = this.oldList.splice(this.oldList.length - 1, 1)[0];
      this.title = this.oldName.splice(this.oldName.length - 1, 1)[0];
      console.log('this.list---', this.list)
      console.log('this.title', this.title)
    },
  },
  mounted() {
    this.getInfo(localStorage.getItem("userId"));
  },
};
</script>

<style lang="less" scoped>
div {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.container {
  background-color: #f1f1f1;
  min-height: 100vh;
  .title {
    width: 100%;
    height: 60px;
    color: #fff;
    text-align: center;
    line-height: 60px;
    font-size: 1.2em;
    background-color: #333333;

    span {
      color: #63BBFD;
      font-size: 14px;
      position: absolute;
      left: 20px;
    }
  }
  .content {
    width: 100%;
    height: calc(100vh - 60px);
    background-color: #f1f1f1;
    padding: 30px 4%;

    .conList {
      width: 100%;
      height: 120px;
      border-radius: 10px;
      margin-bottom: 10px;
      background-color: #fff;
      display: flex;
      justify-content: space-around;
      align-items: center;

      .image {
        width: 80px;
        height: 80px;
        border-radius: 100%;
        overflow: hidden;
        border: 4px solid #bab4b3;

        img {
          width: 100%;
          height: 100%;
        }
      }
      .text {
        font-size: 0.8em;
        color: #333;
        text-align: center;

        div:nth-child(2) {
          margin-top: 5px;
        }
      }
      .number {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: flex-end;

        div:nth-child(2) {
          font-size: 0.8em;
          color: #999;
          margin-top: 5px;
        }
      }
    }
  }
}
</style>